/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ASUS
 */
public class Dataconnection {    
    String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

    String url = "jdbc:sqlserver://localhost:1433;databaseName=BDSChoThue";
    public static Connection DAOConnection = null;
    public static  CallableStatement proc_stmt = null;
    public static  PreparedStatement pre_stmt = null;
    public  static  ResultSet rs = null;
    public Dataconnection() {
        DAOConnection = getConnection();
    }

    private Connection getConnection() {
//        try {
//            Class.forName(driver);
//
//            return DriverManager.getConnection(url, "sa", "123456");                      
//
//        } catch (SQLException ex) {
//            Logger.getLogger(Dataconnection.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (ClassNotFoundException ex) {
//            Logger.getLogger(Dataconnection.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        return null;
        
         try {
             Class.forName(driver);
             //DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
             //jdbc:sqlserver://localhost:1433;databaseName=BDSChoThue
            String dbURL = "jdbc:sqlserver://localhost;databaseName=BDSChoThue";
            String user = "sa";
            String pass = "123456";
            return DriverManager.getConnection(dbURL, user, pass);
 
        }  catch (SQLException ex) {
            Logger.getLogger(Dataconnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Dataconnection.class.getName()).log(Level.SEVERE, null, ex);
        }
         return null;
    }
    
}
